<template>
  <div>
    <!-- <van-nav-bar :title="barTitle" left-arrow fixed :border="false" @click-left="onClickLeft"/> -->
    <div class="nav-container" >
      <div class="padding-content">
        <h3>{{name + '：'}}{{title}}</h3>
        <p class="infos">
          <span>{{user}}</span>
          <span>{{$common.convertDate(date)}}</span>
        </p>
        <div class="rich-text" v-html="content"></div>
        <div v-if="attachment && attachment.length > 0" class="attachment-list">
          <h5><small>附件: </small></h5>
          <p class="van-ellipsis" v-for="item in attachment" @click="previewFile(item)">{{ item.filename }}</p>
        </div>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
  export default{
    data() {
      return{
        type: 1,
        barTitle:'',//页面标题
        rightTitle:'',//页面右边标题
        status: null,//类型
        id: null,//通知、公告ID值
        name:'',
        title:"",//主题
        user:'',
        date:'',
        content:'',
        attachment: [],
        loading:false
      }
    },
    activated() {
      this.type= 1
      this.barTitle= ''//页面标题
      this.rightTitle= ''//页面右边标题
      this.status= null//类型
      this.id= null//通知、公告ID值
      this.name= ''
      this.title= ""//主题
      this.user= ''
      this.date= ''
      this.content= ''
      this.attachment =  []
      this.loading = false
      // this.$bridge.callHandler('navBack')
      this.$bridge.callHandler('navTitle', {title: this.$route.query.type == '3' ? '通知详情' : '公告详情'})
      if(this.$route.query.type == '3'){
        //当前为通知
        this.id = this.$route.query.id
        this.barTitle = '通知详情'
        // this.rightTitle = "全部通知"
        this.showNoticeDetail()
      }else if(this.$route.query.type == '4'){
        //当前为公告
        this.id = this.$route.query.id
        this.barTitle = '公告详情'
        // this.rightTitle = "全部公告"
        this.showProclamationDetail()
      }
    },
    methods:{
      /**
       * 返回键
       * @return {[type]} [description]
       */
      onClickLeft() {
        this.$router.go(-1)
      },
      /**
       * 全部通知，全部公告
       * @return {[type]} [description]
       */
      onClickRight() {
        this.$router.push({ name:'meetingIndex' ,query:{titleType:this.$route.query.type}})
      },
      /**
       * 查询通知详情
       * @return {[type]} [description]
       */
      showNoticeDetail() {

        let config = {
          method: "post",
          url: `${this.$common.basePath}aatp5/public/index.php/message/Notices/workDetail`,
          data: {
            uid: this.$store.state.userId,
            id: this.id
          }
        }
        this.$axios(config).then(res => {
          // console.log(res)
          this.barTitle = '通知详情'
          this.name = "通知"
          this.title = res.data.subject
          this.user = res.data.uid
          this.date = res.data.date
          this.content = res.data.content
          this.attachment = res.data.appendix
          this.loading = true
        }).catch(err => {
          this.$toast(err.msg)
        })
      },
      /**
       * 预览附件
       * @return {[type]} [description]
       */
      previewFile(item) {
        this.$bridge.callHandler('showPreview', {
          url: `${this.$common.filePath}${item.fileaddr}`,
          fileName:  item.filename
        })
        window.open(`${this.$common.filePath}${item.fileaddr}?filename=${item.filename}`)
      },
      /**
       * 查询公告详情
       * @return {[type]} [description]
       */
      showProclamationDetail() {
        let config = {
          method: "post",
          url: `${this.$common.basePath}message/notice.php`,
          data: {
            user_id: this.$store.state.userId,
            type: 'proclamation',
            do: 'detail',
            id: this.id
          }
        }
        this.$axios(config).then(res => {
          // console.log(res)
          this.barTitle = '公告详情'
          this.name = "公告"
          this.title = res.data.subject
          this.user = res.data.user_name
          this.date = res.data.date
          let content = res.data.content          
          this.attachment = res.data.appendix
          this.content = content.replace(/<img src="/g,'<img width="100%" src="'+this.$common.filePath)
        }).catch(err => {
          this.$toast(err.msg)
        })
      }
    }
  }
</script>
<style lang="less">
  .rich-text > * {
    max-width: calc(100vw - 30px)!important;
  }
  .rich-text img {
    display: block;
    max-width: 100%!important;
    height: auto!important;
  }
  .rich-text > table {
    border-collapse: collapse;
    border: 1px solid #e1e1e1;
  }
  .rich-text > table td {
    border: 1px solid #e1e1e1;
  }
</style>
<style type="text/css" lang="less" scoped>
  .padding-content{
    padding-left: 15px;
    padding-right: 15px;
  }
  .infos{
    color: #666666;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
  }
  .rich-text{
    font-size: 17px;
    color: #333333;
  }
  .attachment-list {
    p {
      padding: 15px;
      margin-top: 0;
      background-color: #f5f5f5;
    }
  }
</style>